#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0x7290; /* G11 above "aShuttersoundta" usage @FF96895C */

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) capt_seq_task() {
 asm volatile (
                "STMFD   SP!, {R3-R9,LR}\n"
                "LDR     R6, =0x2C64\n"
                "LDR     R4, =0x38A78\n"
                "MOV     R9, #1\n"
                "MOV     R7, #0\n"

 "loc_FF87B1A0:\n"
                "LDR     R0, [R6,#4]\n"
                "MOV     R2, #0\n"
                "MOV     R1, SP\n"
                "BL      sub_FF83894C\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF87B1CC\n"
                "LDR     R1, =0x5B3\n"
                "LDR     R0, =0xFF87A988\n"
                "BL      sub_FF81E88C\n"
                "BL      sub_FF81E844\n"
                "LDMFD   SP!, {R3-R9,PC}\n"
"loc_FF87B1CC:\n"
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0]\n"
                "CMP     R1, #0x22\n"
                "ADDLS   PC, PC, R1,LSL#2\n"
                "B       loc_FF87B4C4\n"
"loc_FF87B1E0:\n"
                "B       loc_FF87B26C\n"
"loc_FF87B1E4:\n"
                "B       loc_FF87B2D8\n"
"loc_FF87B1E8:\n"
                "B       loc_FF87B314\n"
"loc_FF87B1EC:\n"
                "B       loc_FF87B328\n"
"loc_FF87B1F0:\n"
                "B       loc_FF87B320\n"
"loc_FF87B1F4:\n"
                "B       loc_FF87B330\n"
"loc_FF87B1F8:\n"
                "B       loc_FF87B338\n"
"loc_FF87B1FC:\n"
                "B       loc_FF87B340\n"
"loc_FF87B200:\n"
                "B       loc_FF87B398\n"
"loc_FF87B204:\n"
                "B       loc_FF87B3C0\n"
"loc_FF87B208:\n"
                "B       loc_FF87B3A4\n"
"loc_FF87B20C:\n"
                "B       loc_FF87B3B0\n"
"loc_FF87B210:\n"
                "B       loc_FF87B3B8\n"
"loc_FF87B214:\n"
                "B       loc_FF87B3C8\n"
"loc_FF87B218:\n"
                "B       loc_FF87B3D0\n"
"loc_FF87B21C:\n"
                "B       loc_FF87B3D8\n"
"loc_FF87B220:\n"
                "B       loc_FF87B3E0\n"
"loc_FF87B224:\n"
                "B       loc_FF87B3E8\n"
"loc_FF87B228:\n"
                "B       loc_FF87B3F0\n"
"loc_FF87B22C:\n"
                "B       loc_FF87B3F8\n"
"loc_FF87B230:\n"
                "B       loc_FF87B400\n"
"loc_FF87B234:\n"
                "B       loc_FF87B408\n"
"loc_FF87B238:\n"
                "B       loc_FF87B410\n"
"loc_FF87B23C:\n"
                "B       loc_FF87B41C\n"
"loc_FF87B240:\n"
                "B       loc_FF87B424\n"
"loc_FF87B244:\n"
                "B       loc_FF87B430\n"
"loc_FF87B248:\n"
                "B       loc_FF87B438\n"
"loc_FF87B24C:\n"
                "B       loc_FF87B468\n"
"loc_FF87B250:\n"
                "B       loc_FF87B470\n"
"loc_FF87B254:\n"
                "B       loc_FF87B478\n"
"loc_FF87B258:\n"
                "B       loc_FF87B480\n"
"loc_FF87B25C:\n"
                "B       loc_FF87B488\n"
"loc_FF87B260:\n"
                "B       loc_FF87B490\n"
"loc_FF87B264:\n"
                "B       loc_FF87B49C\n"
"loc_FF87B268:\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B26C:\n"
// ; jumptable FF8"B1D8 entry 0            ; LOCATION: SsPrepareSeq.c:0

                "BL      sub_FF87BADC\n"
                "BL      shooting_expo_param_override\n"  // + 
                "BL      sub_FF878B68\n"

// copied over from SX10 don't know if we need it yet
//  this code added to avoid some incorrect behavior if overrides are used.
//  but it can cause some unexpected side effects. In this case, remove this code!
                 "MOV     R0, #0\n"
                 "STR     R0, [R4,#0x24]\n"  // fixes overrides  behavior at short shutter press
//  end of my code

                "LDR     R0, [R4,#0x24]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF87B4D0\n"
                "BL      sub_FF87A65C\n"
                "MOV     R5, R0\n"
                "LDR     R0, [R4,#0x24]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF87B2B4\n"
                "MOV     R0, #0xC\n"
                "BL      sub_FF8804D8\n"
                "TST     R0, #1\n"
                "STRNE   R9, [R6,#0x10]\n"
                "LDRNE   R0, [R5,#8]\n"
                "ORRNE   R0, R0, #0x40000000\n"
                "STRNE   R0, [R5,#8]\n"
                "BNE     loc_FF87B4D0\n"

"loc_FF87B2B4:\n"
                "MOV     R0, R5\n"
                "BL      sub_FF9680AC\n"
                "MOV     R0, R5\n"
                "BL      sub_FF87AA3C\n"
                "MOV     R0, R5\n"

                //"BL      sub_FF968948\n"
                "BL      sub_FF968948_my\n" //-------->
	         "BL      capt_seq_hook_raw_here\n"      // +				
				
                "TST     R0, #1\n"
                "STRNE   R9, [R6,#0x10]\n"
                "B       loc_FF87B4D0\n"
 
"loc_FF87B2D8:\n"
// ; jumptable FF8"B1D8 entry 1
                "LDR     R0, [R4,#0x24]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF87B304\n"
                "MOV     R0, #0xC\n"
                "BL      sub_FF8804D8\n"
                "TST     R0, #1\n"
                "LDRNE   R0, [SP]\n"
                "MOVNE   R1, #1\n"
                "LDRNE   R2, [R0,#0xC]\n"
                "MOVNE   R0, #1\n"
                "BNE     loc_FF87B390\n"

"loc_FF87B304:\n"
                "LDR     R0, [SP]\n"
              // "BL      sub_FF87AAB4\n"  // - capt_seq_hook ist called in this subroutine	
	        "BL      sub_FF87AAB4_my\n"
"loc_FF87B30C:\n"
                "STR     R7, [R4,#0x24]\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B314:\n"
// ; jumptable FF8"B1D8 entry 2
                "MOV     R0, #1\n"
                "BL      sub_FF87BD8C\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B320:\n"
 //; jumptable FF8"B1D8 entry 4
                "BL      sub_FF87B78C\n"
                "B       loc_FF87B30C\n"
 "loc_FF87B328:\n"
 //; jumptable FF8"B1D8 entry 3
                "BL      sub_FF87BABC\n"
                "B       loc_FF87B30C\n"
"loc_FF87B330:\n"
 //; jumptable FF8"B1D8 entry 5
                "BL      sub_FF87BAC4\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B338:\n"
 //; jumptable FF8"B1D8 entry 6            ; LOCATION: SsPrepareSeq.c:984
                "BL      sub_FF87BC7C\n"
                "B       loc_FF87B39C\n"
"loc_FF87B340:\n"
 //; jumptable FF8"B1D8 entry 7
                "LDR     R5, [R0,#0xC]\n"
                "BL      sub_FF87BACC\n"
                "MOV     R0, R5\n"
                "BL      sub_FF967128\n"
                "TST     R0, #1\n"
                "MOV     R8, R0\n"
                "BNE     loc_FF87B380\n"
                "BL      sub_FF88D890\n"
                "STR     R0, [R5,#0x18]\n"
                "MOV     R0, R5\n"
                "BL      sub_FF968860\n"
                "MOV     R0, R5\n"
                "BL      sub_FF968C60\n"
                "MOV     R8, R0\n"
                "LDR     R0, [R5,#0x18]\n"
                "BL      sub_FF88DAA4\n"

"loc_FF87B380:\n"
                "BL      sub_FF87BABC\n"
                "MOV     R2, R5\n"
                "MOV     R1, #9\n"
                "MOV     R0, R8\n"

"loc_FF87B390:\n"
                "BL      sub_FF879094\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B398:\n"
 //; jumptable FF8"B1D8 entry 8            ; LOCATION: SsPrepareSeq.c:1056
                "BL      sub_FF87BD0C\n"

"loc_FF87B39C:\n"
                "BL      sub_FF878B68\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3A4:\n"
 //; jumptable FF8"B1D8 entry 10
                "LDR     R0, [R4,#0x54]\n"
                "BL      sub_FF87C390\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3B0:\n"
 //; jumptable FF8"B1D8 entry 11           ; LOCATION: SsMovieRec.c:2
                "BL      sub_FF87C638\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3B8:\n"
 //; jumptable FF8"B1D8 entry 12           ; LOCATION: SsMovieRec.c:43
                "BL      sub_FF87C6CC\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3C0:\n"
 //; jumptable FF8"B1D8 entry 9
                "BL      sub_FF87BABC\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3C8:\n"
 //; jumptable FF8"B1D8 entry 13           ; LOCATION: SsAELockSeq.c:195
                "BL      sub_FF967354\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3D0:\n"
 //; jumptable FF8"B1D8 entry 14
                "BL      sub_FF9675AC\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3D8:\n"
 //; jumptable FF8"B1D8 entry 15
                "BL      sub_FF96764C\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3E0:\n"
 //; jumptable FF8"B1D8 entry 16           ; LOCATION: SsExpCompSeq.c:113
                "BL      sub_FF967780\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3E8:\n"
 //; jumptable FF8"B1D8 entry 17
                "BL      sub_FF967874\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B3F0:\n"
 //; jumptable FF8"B1D8 entry 18
                "MOV     R0, #0\n"
                "B       loc_FF87B414\n"
"loc_FF87B3F8:\n"
 //; jumptable FF8"B1D8 entry 19
                "BL      sub_FF967DF0\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B400:\n"
 //; jumptable FF8"B1D8 entry 20           ; LOCATION: SsMFSeq.c:110
                "BL      sub_FF967E80\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B408:\n"
 //; jumptable FF8"B1D8 entry 21           ; LOCATION: SsMFSeq.c:177
                "BL      sub_FF967F40\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B410:\n"
 //; jumptable FF8"B1D8 entry 22
                "MOV     R0, #1\n"

"loc_FF87B414:\n"
                "BL      sub_FF967CA0\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B41C:\n"
 //; jumptable FF8"B1D8 entry 23
                "BL      sub_FF87BFA8\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B424:\n"
 //; jumptable FF8"B1D8 entry 24
                "BL      sub_FF87C048\n"
                "BL      sub_FF87B5F8\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B430:\n"
 //; jumptable FF8"B1D8 entry 25           ; LOCATION: SsChgExpSeq.c:0
                "BL      sub_FF967B2C\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B438:\n"
 //; jumptable FF8"B1D8 entry 26
                "MOV     R2, #2\n"
                "ADD     R1, R4, #0x62\n"
                "MOV     R0, #0x6F\n"
                "BL      sub_FF88D700\n"
                "TST     R0, #1\n"
                "LDRNE   R1, =0x6AA\n"
                "LDRNE   R0, =0xFF87A988\n"
                "BLNE    sub_FF81E88C\n"
                "LDRH    R0, [R4,#0x62]\n"
                "CMP     R0, #1\n"
                "BLEQ    sub_FF967B20\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B468:\n"
 //; jumptable FF8"B1D8 entry 27           ; LOCATION: SsChgExpSeq.c:0
                "BL      sub_FF967BD0\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B470:\n"
 //; jumptable FF8"B1D8 entry 28
                "BL      sub_FF87A914\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B478:\n"
 //; jumptable FF8"B1D8 entry 29
                "BL      sub_FF83657C\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B480:\n"
 //; jumptable FF8"B1D8 entry 30
                "BL      sub_FF87EA84\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B488:\n"
 //; jumptable FF8"B1D8 entry 31
                "BL      sub_FF87EAEC\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B490:\n"
 //; jumptable FF8"B1D8 entry 32
                "BL      sub_FF87EB48\n"
                "BL      sub_FF87EB08\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B49C:\n"
 //; jumptable FF8"B1D8 entry 33
                "MOV     R0, #1\n"
                "BL      sub_FF9694C8\n"
                "MOV     R0, #1\n"
                "BL      sub_FF9695D8\n"
                "LDRH    R0, [R4,#0xA0]\n"
                "CMP     R0, #4\n"
                "BNE     loc_FF87B4D0\n"
                "BL      sub_FF87EAEC\n"
                "BL      sub_FF87EF34\n"
                "B       loc_FF87B4D0\n"
"loc_FF87B4C4:\n"
 //; jumptable FF8"B1D8 default entry
                "LDR     R1, =0x708\n"
                "LDR     R0, =0xFF87A988\n"
                "BL      sub_FF81E88C\n"

"loc_FF87B4D0:\n"
 //; jumptable FF8"B1D8 entry 34
                "LDR     R0, [SP]\n"
                "LDR     R1, [R0,#4]\n"
                "LDR     R0, [R6]\n"
                "BL      sub_FF885538\n"
                "LDR     R5, [SP]\n"
                "LDR     R0, [R5,#8]\n"
                "CMP     R0, #0\n"
                "LDREQ   R1, =0x131\n"
                "LDREQ   R0, =0xFF87A988\n"
                "BLEQ    sub_FF81E88C\n"
                "STR     R7, [R5,#8]\n"
                "B       loc_FF87B1A0\n"
 );
}


void __attribute__((naked,noinline)) sub_FF87AAB4_my() {
 asm volatile (
               "STMFD   SP!, {R3-R9,LR}\n"
               "LDR     R4, [R0,#0xC]\n"
               "LDR     R5, =0x38A78\n"
               "LDR     R0, [R4,#8]\n"
               "LDR     R6, =0x420A\n"
               "ORR     R0, R0, #1\n"
               "STR     R0, [R4,#8]\n"
               "LDRH    R0, [R5]\n"
               "LDR     R8, =0x2C64\n"
               "MOV     R7, #0\n"
               "CMP     R0, R6\n"
               "BEQ     loc_FF87AB58\n"
               "LDRH    R0, [R5,#0x9E]\n"
               "CMP     R0, #3\n"
               "BEQ     loc_FF87ABB8\n"
               "LDR     R0, [R4,#0xC]\n"
               "CMP     R0, #1\n"
               "BLS     loc_FF87AB64\n"
               "LDRH    R0, [R5,#0x9C]\n"
               "CMP     R0, #0\n"
               "BNE     loc_FF87ABB8\n"
               "LDRH    R0, [R5,#0x98]\n"
               "CMP     R0, #2\n"
               "BNE     loc_FF87AB70\n"
               "BL      sub_FF87C0F8\n"
               "LDRH    R0, [R5]\n"
               "CMP     R0, R6\n"
               "BEQ     loc_FF87AB58\n"
               "LDRH    R0, [R5,#0x9E]\n"
               "CMP     R0, #3\n"
               "BEQ     loc_FF87ABB8\n"
               "LDR     R0, [R4,#0xC]\n"
               "CMP     R0, #1\n"
               "BLS     loc_FF87AB64\n"
               "LDRH    R0, [R5,#0x9C]\n"
               "CMP     R0, #0\n"
               "BNE     loc_FF87ABB8\n"
               "LDRH    R0, [R5,#0x98]\n"
               "CMP     R0, #2\n"
               "BEQ     loc_FF87AB9C\n"
               "B       loc_FF87AB70\n"
"loc_FF87AB58:\n"
               "LDRH    R0, [R5,#0x9E]\n"
               "CMP     R0, #3\n"
               "BEQ     loc_FF87ABB8\n"
"loc_FF87AB64:\n"
               "LDRH    R0, [R5,#0x9C]\n"
               "CMP     R0, #0\n"
	       "BNE     loc_FF87ABB8\n"
"loc_FF87AB70:\n"
               "LDRH    R0, [R5,#0x98]\n"
               "CMP     R0, #1\n"
               "BNE     loc_FF87ABB8\n"
	       "LDRH    R0, [R5]\n"
               "CMP     R0, R6\n"
               "LDRNE   R0, [R4,#0xC]\n"
               "CMPNE   R0, #1\n"
	       "BLS     loc_FF87ABB8\n"
               "LDR     R0, [R4,#0x10]\n"
               "CMP     R0, #1\n"
               "BNE     loc_FF87ABB8\n"
"loc_FF87AB9C:\n"
                "MOV     R3, #0x268\n"
                "STR     R3, [SP]\n"
                "LDR     R0, [R8]\n"
                "LDR     R2, =0xEA60\n"
                "LDR     R3, =0xFF87A988\n"
                "MOV     R1, #0x40000000\n"
		"BL      sub_FF880840\n"

"loc_FF87ABB8:\n"
                "BL      sub_FF87A914\n"
                "LDR     R0, [R5,#0x24]\n"
                "CMP     R0, #0\n"
                "MOVEQ   R0, #2\n"
                "BLEQ    sub_FF876CF8\n"
                "BL      sub_FF87BACC\n"
                "LDR     R0, [R5,#0x24]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF87AC70\n"
                "MOV     R0, #0\n"
                "BL      sub_FF9694C8\n"
                "MOV     R0, #0\n"
                "BL      sub_FF9695D8\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9680AC\n"
                "MOV     R0, R4\n"
                "BL      sub_FF87BF24\n"
                "MOV     R0, R4\n"
                "BL      sub_FF966CDC\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF87AC38\n"
                "BL      sub_FF969508\n"
                "BL      sub_FF96961C\n"
                "BL      sub_FF96966C\n"
                "MOV     R0, R4\n"
                "BL      sub_FF966E54\n"
                "TST     R0, #1\n"
                "MOVNE   R2, R4\n"
                "LDMNEFD SP!, {R3-R9,LR}\n"
                "MOVNE   R1, #1\n"
                "BNE     sub_FF879094\n"
                "B       loc_FF87AC4C\n"
"loc_FF87AC38:\n"
                "MOV     R0, R4\n"
                "BL      sub_FF966DC0\n"
                "BL      sub_FF969508\n"
                "BL      sub_FF96961C\n"
                "BL      sub_FF96966C\n"
"loc_FF87AC4C:\n"
                "MOV     R0, R4\n"
                "BL      sub_FF87AA3C\n"
                "MOV     R0, R4\n"
                "BL      sub_FF968860\n"
                "BL      sub_FF9692E0\n"
                "MOV     R0, R4\n"
                //"BL      sub_FF968948\n"
		"BL      sub_FF968948_my\n"
                "MOV     R7, R0\n"
		"BL      capt_seq_hook_raw_here\n"      // +
                "B       loc_FF87AC7C\n"
"loc_FF87AC70:\n"
                "LDR     R0, [R8,#0x10]\n"
                "CMP     R0, #0\n"
                "MOVNE   R7, #0x1D\n"

"loc_FF87AC7C:\n"
                "BL      sub_FF87EAEC\n"
                "BL      sub_FF87EB34\n"
                "BL      sub_FF87EB74\n"
                "MOV     R2, R4\n"
                "MOV     R1, #1\n"
                "MOV     R0, R7\n"
                "BL      sub_FF879094\n"
                "BL      sub_FF968C04\n"
                "CMP     R0, #0\n"
                "LDRNE   R0, [R4,#8]\n"
                "ORRNE   R0, R0, #0x2000\n"
                "STRNE   R0, [R4,#8]\n"
                "LDRH    R0, [R5,#0x9E]\n"
                "CMP     R0, #3\n"
                "BEQ     locret_FF87ACD4\n"
                "LDRH    R0, [R5,#0x9C]\n"
                "CMP     R0, #0\n"
                "LDREQH  R0, [R5,#0x98]\n"
                "CMPEQ   R0, #2\n"
                "MOVEQ   R0, R4\n"
                "LDMEQFD SP!, {R3-R9,LR}\n"
                "BEQ     sub_FF87C14C\n"
"locret_FF87ACD4:\n"
                "LDMFD   SP!, {R3-R9,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FF968948_my() {
 asm volatile (
                "STMFD   SP!, {R0-R8,LR}\n"
                "MOV     R4, R0\n"
                "BL      sub_FF9697C4\n"
                //"MOV     R1, 0xFFFFFFFF\n"
		"LDR    R1,=0xFFFFFFFF\n"
                "BL      sub_FF88556C\n"
                "LDR     R5, =0x7290\n"
                "LDR     R0, [R5,#0xC]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF968998\n"
                "MOV     R1, #1\n"
                "MOV     R0, #0\n"
                "BL      sub_FF839194\n"
                "STR     R0, [R5,#0xC]\n"
                "MOV     R3, #0\n"
                "STR     R3, [SP]\n"
                "LDR     R3, =0xFF9682D4\n"
                "LDR     R0, =0xFF968BC8\n"
                "MOV     R2, #0x400\n"
                "MOV     R1, #0x17\n"
                "BL      sub_FF839160\n"
"loc_FF968998:\n"
                "MOV     R2, #4\n"
                "ADD     R1, SP, #8\n"
                "MOV     R0, #0x8A\n"
                "BL      sub_FF88D700\n"
                "TST     R0, #1\n"
                "LDRNE   R1, =0x3C5\n"
                "LDRNE   R0, =0xFF96856C\n"
                "BLNE    sub_FF81E88C\n"
                "LDR     R6, =0x38B44\n"
                "LDR     R8, =0x38A78\n"
                "LDR     R3, [R6]\n"
                "LDRSH   R2, [R6,#0xC]\n"
                "LDRSH   R1, [R6,#0xE]\n"
                "LDR     R0, [R8,#0x94]\n"
                "BL      sub_FF92FC80\n"
                "BL      sub_FF863564\n"
                "LDR     R3, =0x7298\n"
                "STRH    R0, [R4,#0xA4]\n"
                "SUB     R2, R3, #4\n"
                "STRD    R2, [SP]\n"
                "MOV     R1, R0\n"
                "LDRH    R0, [R8,#0x5C]\n"
                "LDRSH   R2, [R6,#0xC]\n"
                "SUB     R3, R3, #8\n"
		"BL      sub_FF96B44C\n"
                "BL      wait_until_remote_button_is_released\n"  // +
                "BL      capt_seq_hook_set_nr\n"                  // +   
                "B       sub_FF9689FC\n" // +  Jump back to original FW code
 );
}

void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
 
               "STMFD   SP!, {R4-R8,LR}\n"
               "SUB     SP, SP, #0x20\n"
               "LDR     R8, =0xBB8\n"
               "LDR     R7, =0x4530\n"
               "LDR     R5, =0x42240\n"
               "MOV     R0, #0\n"
               "ADD     R6, SP, #0x10\n"
               "STR     R0, [SP,#0xC]\n"

"loc_FF8BFC18:\n"
               "LDR     R0, [R7,#0x20]\n"
               "MOV     R2, #0\n"
               "ADD     R1, SP, #0x1C\n"
               "BL      sub_FF83894C\n"
               "LDR     R0, [SP,#0xC]\n"
               "CMP     R0, #1\n"
               "BNE     loc_FF8BFC64\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R0, [R0]\n"
               "CMP     R0, #0x13\n"
               "CMPNE   R0, #0x14\n"
               "CMPNE   R0, #0x15\n"
               "CMPNE   R0, #0x16\n"
               "BEQ     loc_FF8BFDC8\n"
               "CMP     R0, #0x28\n"
               "BEQ     loc_FF8BFD50\n"
               "ADD     R1, SP, #0xC\n"
               "MOV     R0, #0\n"
               "BL      sub_FF8BFBA8\n"
"loc_FF8BFC64:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R1, [R0]\n"
               "CMP     R1, #0x2E\n"
               "BNE     loc_FF8BFC94\n"
               "LDR     R0, [SP,#0x1C]\n"
               "BL      sub_FF8C0EFC\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R1, #1\n"
               "BL      sub_FF885538\n"
               "BL      sub_FF81E844\n"
               "ADD     SP, SP, #0x20\n"
               "LDMFD   SP!, {R4-R8,PC}\n"
"loc_FF8BFC94:\n"
               "CMP     R1, #0x2D\n"
               "BNE     loc_FF8BFCB0\n"
               "LDR     R2, [R0,#0x8C]!\n"
               "LDR     R1, [R0,#4]\n"
               "MOV     R0, R1\n"
               "BLX     R2\n"
               "B       loc_FF8C01F0\n"
"loc_FF8BFCB0:\n"
               "CMP     R1, #0x26\n"
               "BNE     loc_FF8BFD00\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R1, #0x80\n"
               "BL      sub_FF88556C\n"
               "LDR     R0, =0xFF8BC338\n"
               "MOV     R1, #0x80\n"
               "BL      sub_FF95B5BC\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R2, R8\n"
               "MOV     R1, #0x80\n"
               "BL      sub_FF885478\n"
               "TST     R0, #1\n"
               "LDRNE   R1, =0xE5F\n"
               "BNE     loc_FF8BFDBC\n"
"loc_FF8BFCEC:\n"
               "LDR     R1, [SP,#0x1C]\n"
               "LDR     R0, [R1,#0x90]\n"
               "LDR     R1, [R1,#0x8C]\n"
               "BLX     R1\n"
               "B       loc_FF8C01F0\n"
"loc_FF8BFD00:\n"
               "CMP     R1, #0x27\n"
               "BNE     loc_FF8BFD48\n"
               "ADD     R1, SP, #0xC\n"
               "BL      sub_FF8BFBA8\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R1, #0x100\n"
               "BL      sub_FF88556C\n"
               "LDR     R0, =0xFF8BC348\n"
               "MOV     R1, #0x100\n"
               "BL      sub_FF95BF4C\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R2, R8\n"
               "MOV     R1, #0x100\n"
               "BL      sub_FF885478\n"
               "TST     R0, #1\n"
               "BEQ     loc_FF8BFCEC\n"
               "LDR     R1, =0xE69\n"
               "B       loc_FF8BFDBC\n"
"loc_FF8BFD48:\n"
               "CMP     R1, #0x28\n"
               "BNE     loc_FF8BFD60\n"

"loc_FF8BFD50:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "ADD     R1, SP, #0xC\n"
               "BL      sub_FF8BFBA8\n"
               "B       loc_FF8BFCEC\n"
"loc_FF8BFD60:\n"
               "CMP     R1, #0x2B\n"
               "BNE     loc_FF8BFD78\n"
               "BL      sub_FF8AF79C\n"
               "BL      sub_FF8B03C0\n"
               "BL      sub_FF8AFF14\n"
               "B       loc_FF8BFCEC\n"
"loc_FF8BFD78:\n"
               "CMP     R1, #0x2C\n"
               "BNE     loc_FF8BFDC8\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R1, #4\n"
               "BL      sub_FF88556C\n"
               "LDR     R1, =0xFF8BC368\n"
               "LDR     R0, =0xFFFFF400\n"
               "MOV     R2, #4\n"
               "BL      sub_FF8AF218\n"
               "BL      sub_FF8AF4A0\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R2, R8\n"
               "MOV     R1, #4\n"
               "BL      sub_FF885394\n"
               "TST     R0, #1\n"
               "BEQ     loc_FF8BFCEC\n"
               "LDR     R1, =0xE91\n"
"loc_FF8BFDBC:\n"
               "LDR     R0, =0xFF8BC9A8\n"
               "BL      sub_FF81E88C\n"
               "B       loc_FF8BFCEC\n"
"loc_FF8BFDC8:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "MOV     R4, #1\n"
               "LDR     R1, [R0]\n"
               "CMP     R1, #0x11\n"
               "CMPNE   R1, #0x12\n"
               "BNE     loc_FF8BFE38\n"
               "LDR     R1, [R0,#0x7C]\n"
               "ADD     R1, R1, R1,LSL#1\n"
               "ADD     R1, R0, R1,LSL#2\n"
               "SUB     R1, R1, #8\n"
               "LDMIA   R1, {R2-R4}\n"
               "STMIA   R6, {R2-R4}\n"
               "BL      sub_FF8BE520\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R1, [R0,#0x7C]\n"
               "LDR     R3, [R0,#0x8C]\n"
               "LDR     R2, [R0,#0x90]\n"
               "ADD     R0, R0, #4\n"
               "BLX     R3\n"
               "LDR     R0, [SP,#0x1C]\n"
               "BL      sub_FF8C12C4\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R1, [R0,#0x7C]\n"
               "LDR     R3, [R0,#0x94]\n"
               "LDR     R2, [R0,#0x98]\n"
               "ADD     R0, R0, #4\n"
               "BLX     R3\n"
               "B       loc_FF8C0130\n"
"loc_FF8BFE38:\n"
               "CMP     R1, #0x13\n"
               "CMPNE   R1, #0x14\n"
               "CMPNE   R1, #0x15\n"
               "CMPNE   R1, #0x16\n"
               "BNE     loc_FF8BFEF0\n"
               "ADD     R3, SP, #0xC\n"
               "MOV     R2, SP\n"
               "ADD     R1, SP, #0x10\n"
               "BL      sub_FF8BE7FC\n"
               "CMP     R0, #1\n"
               "MOV     R4, R0\n"
               "CMPNE   R4, #5\n"
               "BNE     loc_FF8BFE8C\n"
               "LDR     R0, [SP,#0x1C]\n"
               "MOV     R2, R4\n"
               "LDR     R1, [R0,#0x7C]!\n"
               "LDR     R12, [R0,#0x10]!\n"
               "LDR     R3, [R0,#4]\n"
               "MOV     R0, SP\n"
               "BLX     R12\n"
               "B       loc_FF8BFEC4\n"
"loc_FF8BFE8C:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "CMP     R4, #2\n"
               "LDR     R3, [R0,#0x90]\n"
               "CMPNE   R4, #6\n"
               "BNE     loc_FF8BFED8\n"
               "LDR     R12, [R0,#0x8C]\n"
               "MOV     R0, SP\n"
               "MOV     R2, R4\n"
               "MOV     R1, #1\n"
               "BLX     R12\n"
               "LDR     R0, [SP,#0x1C]\n"
               "MOV     R2, SP\n"
               "ADD     R1, SP, #0x10\n"
               "BL      sub_FF8BF8B4\n"

"loc_FF8BFEC4:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R2, [SP,#0xC]\n"
               "MOV     R1, R4\n"
               "BL      sub_FF8BFB48\n"
               "B       loc_FF8C0130\n"
"loc_FF8BFED8:\n"
               "LDR     R1, [R0,#0x7C]\n"
               "LDR     R12, [R0,#0x8C]\n"
               "ADD     R0, R0, #4\n"
               "MOV     R2, R4\n"
               "BLX     R12\n"
               "B       loc_FF8C0130\n"
"loc_FF8BFEF0:\n"
               "CMP     R1, #0x22\n"
               "CMPNE   R1, #0x23\n"
               "BNE     loc_FF8BFF3C\n"
               "LDR     R1, [R0,#0x7C]\n"
               "ADD     R1, R1, R1,LSL#1\n"
               "ADD     R1, R0, R1,LSL#2\n"
               "SUB     R1, R1, #8\n"
               "LDMIA   R1, {R2-R4}\n"
               "STMIA   R6, {R2-R4}\n"
               "BL      sub_FF8BDA64\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R1, [R0,#0x7C]\n"
               "LDR     R3, [R0,#0x8C]\n"
               "LDR     R2, [R0,#0x90]\n"
               "ADD     R0, R0, #4\n"
               "BLX     R3\n"
               "LDR     R0, [SP,#0x1C]\n"
               "BL      sub_FF8BDD64\n"
               "B       loc_FF8C0130\n"
"loc_FF8BFF3C:\n"
               "ADD     R1, R0, #4\n"
               "LDMIA   R1, {R2,R3,R12}\n"
               "STMIA   R6, {R2,R3,R12}\n"
               "LDR     R1, [R0]\n"
               "CMP     R1, #0x25\n"
               "ADDLS   PC, PC, R1,LSL#2\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFF58:\n"
               "B       loc_FF8BFFF0\n"
"loc_FF8BFF5C:\n"
               "B       loc_FF8BFFF0\n"
"loc_FF8BFF60:\n"
               "B       loc_FF8BFFF8\n"
"loc_FF8BFF64:\n"
               "B       loc_FF8C0000\n"
"loc_FF8BFF68:\n"
               "B       loc_FF8C0000\n"
"loc_FF8BFF6C:\n"
               "B       loc_FF8C0000\n"
"loc_FF8BFF70:\n"
               "B       loc_FF8BFFF0\n"
"loc_FF8BFF74:\n"
               "B       loc_FF8BFFF8\n"
"loc_FF8BFF78:\n"
               "B       loc_FF8C0000\n"
"loc_FF8BFF7C:\n"
               "B       loc_FF8C0000\n"
"loc_FF8BFF80:\n"
               "B       loc_FF8C0018\n"
"loc_FF8BFF84:\n"
               "B       loc_FF8C0018\n"
"loc_FF8BFF88:\n"
               "B       loc_FF8C0104\n"
"loc_FF8BFF8C:\n"
               "B       loc_FF8C010C\n"
"loc_FF8BFF90:\n"
               "B       loc_FF8C010C\n"
"loc_FF8BFF94:\n"
               "B       loc_FF8C010C\n"
"loc_FF8BFF98:\n"
               "B       loc_FF8C010C\n"
"loc_FF8BFF9C:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFA0:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFA4:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFA8:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFAC:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFB0:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFB4:\n"
               "B       loc_FF8C0008\n"
"loc_FF8BFFB8:\n"
               "B       loc_FF8C0010\n"
"loc_FF8BFFBC:\n"
               "B       loc_FF8C0010\n"
"loc_FF8BFFC0:\n"
               "B       loc_FF8C0024\n"
"loc_FF8BFFC4:\n"
               "B       loc_FF8C0024\n"
"loc_FF8BFFC8:\n"
               "B       loc_FF8C002C\n"
"loc_FF8BFFCC:\n"
               "B       loc_FF8C005C\n"
"loc_FF8BFFD0:\n"
               "B       loc_FF8C008C\n"
"loc_FF8BFFD4:\n"
               "B       loc_FF8C00BC\n"
"loc_FF8BFFD8:\n"
               "B       loc_FF8C00EC\n"
"loc_FF8BFFDC:\n"
               "B       loc_FF8C00EC\n"
"loc_FF8BFFE0:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFE4:\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFE8:\n"
               "B       loc_FF8C00F4\n"
"loc_FF8BFFEC:\n"
               "B       loc_FF8C00FC\n"
"loc_FF8BFFF0:\n"
//; jumptable FF8"FF50 entries 0,1,6      ; LOCATION: ExpDrv.c:2
               "BL      sub_FF8BC850\n"
               "B       loc_FF8C0110\n"
"loc_FF8BFFF8:\n"
//; jumptable FF8"FF50 entries 2,7        ; LOCATION: ExpDrv.c:0
               "BL      sub_FF8BCAD4\n"
               "B       loc_FF8C0110\n"
"loc_FF8C0000:\n"
//; jumptable FF8"FF50 entries 3-5,8,9    ; LOCATION: ExpDrv.c:0
               "BL      sub_FF8BCCDC\n"
               "B       loc_FF8C0110\n"
"loc_FF8C0008:\n"
//; jumptable FF8"FF50 entry 23           ; LOCATION: ExpDrv.c:2
               "BL      sub_FF8BCF54\n"
               "B       loc_FF8C0110\n"
"loc_FF8C0010:\n"
//; jumptable FF8"FF50 entries 24,25      ; LOCATION: ExpDrv.c:0
               "BL      sub_FF8BD14C\n"
               "B       loc_FF8C0110\n"
"loc_FF8C0018:\n"
//; jumptable FF8"FF50 entries 10,11      ; LOCATION: ExpDrv.c:2
               //"BL      sub_FF8BD408\n"
			   "BL      sub_FF8BD408_my\n" // +-------------------->
               "MOV     R4, #0\n"
               "B       loc_FF8C0110\n"
"loc_FF8C0024:\n"
//; jumptable FF8"FF50 entries 26,27      ; LOCATION: ExpDrv.c:0
               "BL      sub_FF8BD548\n"
               "B       loc_FF8C0110\n"
"loc_FF8C002C:\n"
//jumptable FF8"FF50 entry 28
               "LDRH    R1, [R0,#4]\n"
               "STRH    R1, [SP,#0x10]\n"
               "LDRH    R1, [R5,#2]\n"
               "STRH    R1, [SP,#0x12]\n"
               "LDRH    R1, [R5,#4]\n"
               "STRH    R1, [SP,#0x14]\n"
               "LDRH    R1, [R5,#6]\n"
               "STRH    R1, [SP,#0x16]\n"
               "LDRH    R1, [R0,#0xC]\n"
               "STRH    R1, [SP,#0x18]\n"
               "BL      sub_FF8C0F70\n"
               "B       loc_FF8C0110\n"
"loc_FF8C005C:\n"
//; jumptable FF8"FF50 entry 29
               "LDRH    R1, [R0,#4]\n"
               "STRH    R1, [SP,#0x10]\n"
               "LDRH    R1, [R5,#2]\n"
               "STRH    R1, [SP,#0x12]\n"
               "LDRH    R1, [R5,#4]\n"
               "STRH    R1, [SP,#0x14]\n"
               "LDRH    R1, [R5,#6]\n"
               "STRH    R1, [SP,#0x16]\n"
               "LDRH    R1, [R5,#8]\n"
               "STRH    R1, [SP,#0x18]\n"
               "BL      sub_FF8C10DC\n"
               "B       loc_FF8C0110\n"
"loc_FF8C008C:\n"
//; jumptable FF8"FF50 entry 30
               "LDRH    R1, [R5]\n"
               "STRH    R1, [SP,#0x10]\n"
               "LDRH    R1, [R0,#6]\n"
               "STRH    R1, [SP,#0x12]\n"
               "LDRH    R1, [R5,#4]\n"
               "STRH    R1, [SP,#0x14]\n"
               "LDRH    R1, [R5,#6]\n"
               "STRH    R1, [SP,#0x16]\n"
               "LDRH    R1, [R5,#8]\n"
               "STRH    R1, [SP,#0x18]\n"
               "BL      sub_FF8C1188\n"
               "B       loc_FF8C0110\n"
"loc_FF8C00BC:\n"
//; jumptable FF8"FF50 entry 31
               "LDRH    R1, [R5]\n"
               "STRH    R1, [SP,#0x10]\n"
               "LDRH    R1, [R5,#2]\n"
               "STRH    R1, [SP,#0x12]\n"
               "LDRH    R1, [R5,#4]\n"
               "STRH    R1, [SP,#0x14]\n"
               "LDRH    R1, [R5,#6]\n"
               "STRH    R1, [SP,#0x16]\n"
               "LDRH    R1, [R0,#0xC]\n"
               "STRH    R1, [SP,#0x18]\n"
               "BL      sub_FF8C1228\n"
               "B       loc_FF8C0110\n"
"loc_FF8C00EC:\n"
//; jumptable FF8"FF50 entries 32,33      ; LOCATION: ExpDrv.c:0
               "BL      sub_FF8BD8A0\n"
               "B       loc_FF8C0110\n"
"loc_FF8C00F4:\n"
//; jumptable FF8"FF50 entry 36           ; LOCATION: ExpDrv.c:10
               "BL      sub_FF8BDE68\n"
               "B       loc_FF8C0110\n"
"loc_FF8C00FC:\n"
//; jumptable FF8"FF50 entry 37           ; LOCATION: ExpDrv.c:0
               "BL      sub_FF8BE0A4\n"
               "B       loc_FF8C0110\n"
"loc_FF8C0104:\n"
//; jumptable FF8"FF50 entry 12           ; LOCATION: ExpDrv.c:2
               "BL      sub_FF8BE220\n"
               "B       loc_FF8C0110\n"
"loc_FF8C010C:\n"
//; jumptable FF8"FF50 entries 13-16      ; LOCATION: ExpDrv.c:128
               "BL      sub_FF8BE3BC\n"

"loc_FF8C0110:\n"
//; jumptable FF8"FF50 default entry
//; jumptable FF8"FF50 entries 17-22,34,35
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R1, [R0,#0x7C]\n"
               "LDR     R3, [R0,#0x8C]\n"
               "LDR     R2, [R0,#0x90]\n"
               "ADD     R0, R0, #4\n"
               "BLX     R3\n"
               "CMP     R4, #1\n"
               "BNE     loc_FF8C0178\n"

"loc_FF8C0130:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "MOV     R2, #0xC\n"
               "LDR     R1, [R0,#0x7C]\n"
               "ADD     R1, R1, R1,LSL#1\n"
               "ADD     R0, R0, R1,LSL#2\n"
               "SUB     R4, R0, #8\n"
               "LDR     R0, =0x42240\n"
               "ADD     R1, SP, #0x10\n"
               "BL      sub_FFB3C9E0\n"
               "LDR     R0, =0x4224C\n"
               "MOV     R2, #0xC\n"
               "ADD     R1, SP, #0x10\n"
               "BL      sub_FFB3C9E0\n"
               "LDR     R0, =0x42258\n"
               "MOV     R2, #0xC\n"
               "MOV     R1, R4\n"
               "BL      sub_FFB3C9E0\n"
               "B       loc_FF8C01F0\n"
"loc_FF8C0178:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "LDR     R0, [R0]\n"
               "CMP     R0, #0xB\n"
               "BNE     loc_FF8C01C0\n"
               "MOV     R3, #0\n"
               "STR     R3, [SP]\n"
               "MOV     R3, #1\n"
               "MOV     R2, #1\n"
               "MOV     R1, #1\n"
               "MOV     R0, #0\n"
               "BL      sub_FF8BC658\n"
               "MOV     R3, #0\n"
               "STR     R3, [SP]\n"
               "MOV     R3, #1\n"
               "MOV     R2, #1\n"
               "MOV     R1, #1\n"
               "MOV     R0, #0\n"
               "B       loc_FF8C01EC\n"
"loc_FF8C01C0:\n"
               "MOV     R3, #1\n"
               "MOV     R2, #1\n"
               "MOV     R1, #1\n"
               "MOV     R0, #1\n"
               "STR     R3, [SP]\n"
               "BL      sub_FF8BC658\n"
               "MOV     R3, #1\n"
               "MOV     R2, #1\n"
               "MOV     R1, #1\n"
               "MOV     R0, #1\n"
               "STR     R3, [SP]\n"

"loc_FF8C01EC:\n"
               "BL      sub_FF8BC798\n"

"loc_FF8C01F0:\n"
               "LDR     R0, [SP,#0x1C]\n"
               "BL      sub_FF8C0EFC\n"
               "B       loc_FF8BFC18\n"
);
};

void __attribute__((naked,noinline)) sub_FF8BD408_my(){
 asm volatile(
               "STMFD   SP!, {R4-R8,LR}\n"
               "LDR     R7, =0x4530\n"
               "MOV     R4, R0\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R1, #0x3E\n"
               "BL      sub_FF88556C\n"
               "LDRSH   R0, [R4,#4]\n"
               "MOV     R2, #0\n"
               "MOV     R1, #0\n"
               "BL      sub_FF8BC3BC\n"
               "MOV     R6, R0\n"
               "LDRSH   R0, [R4,#6]\n"
               "BL      sub_FF8BC4CC\n"
               "LDRSH   R0, [R4,#8]\n"
               "BL      sub_FF8BC524\n"
               "LDRSH   R0, [R4,#0xA]\n"
               "BL      sub_FF8BC57C\n"
               "LDRSH   R0, [R4,#0xC]\n"
               "MOV     R1, #0\n"
               "BL      sub_FF8BC5D4\n"
               "MOV     R5, R0\n"
               "LDR     R0, [R4]\n"
               "LDR     R8, =0x42258\n"
               "CMP     R0, #0xB\n"
               "MOVEQ   R6, #0\n"
               "MOVEQ   R5, #0\n"
               "BEQ     loc_FF8BD49C\n"
               "CMP     R6, #1\n"
               "BNE     loc_FF8BD49C\n"
               "LDRSH   R0, [R4,#4]\n"
               "LDR     R1, =0xFF8BC328\n"
               "MOV     R2, #2\n"
               "BL      sub_FF95B908\n"
               "STRH    R0, [R4,#4]\n"
               "MOV     R0, #0\n"
               "STR     R0, [R7,#0x28]\n"
               "B       loc_FF8BD4A4\n"
"loc_FF8BD49C:\n"
               "LDRH    R0, [R8]\n"
               "STRH    R0, [R4,#4]\n"

"loc_FF8BD4A4:\n"
               "CMP     R5, #1\n"
               "LDRNEH  R0, [R8,#8]\n"
               "BNE     loc_FF8BD4C0\n"
               "LDRSH   R0, [R4,#0xC]\n"
               "LDR     R1, =0xFF8BC3AC\n"
               "MOV     R2, #0x20\n"
               "BL      sub_FF8C0F2C\n"
"loc_FF8BD4C0:\n"
               "STRH    R0, [R4,#0xC]\n"
               "LDRSH   R0, [R4,#6]\n"
               //"BL      sub_FF8AF50C"
			   "BL      sub_FF8AF50C_my\n" // + ------------------>
               "LDRSH   R0, [R4,#8]\n"
               "MOV     R1, #1\n"
               "BL      sub_FF8AFC5C\n"
               "MOV     R1, #0\n"
               "ADD     R0, R4, #8\n"
               "BL      sub_FF8AFCE4\n"
               "LDRSH   R0, [R4,#0xE]\n"
               "BL      sub_FF8B77C8\n"
               "LDR     R4, =0xBB8\n"
               "CMP     R6, #1\n"
               "BNE     loc_FF8BD518\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R2, R4\n"
               "MOV     R1, #2\n"
               "BL      sub_FF885478\n"
               "TST     R0, #1\n"
               "LDRNE   R1, =0x5A3\n"
               "LDRNE   R0, =0xFF8BC9A8\n"
               "BLNE    sub_FF81E88C\n"

"loc_FF8BD518:\n"
               "CMP     R5, #1\n"
               "LDMNEFD SP!, {R4-R8,PC}\n"
               "LDR     R0, [R7,#0x1C]\n"
               "MOV     R2, R4\n"
               "MOV     R1, #0x20\n"
               "BL      sub_FF885478\n"
               "TST     R0, #1\n"
               "LDRNE   R1, =0x5A8\n"
               "LDRNE   R0, =0xFF8BC9A8\n"
               "LDMNEFD SP!, {R4-R8,LR}\n"
               "BNE     sub_FF81E88C\n"
               "LDMFD   SP!, {R4-R8,PC}\n"
 );
};
void __attribute__((naked,noinline)) sub_FF8AF50C_my()
{  
 asm volatile(
                "STMFD   SP!, {R4-R6,LR}\n"
                "LDR     R5, =0x4240\n"
                "MOV     R4, R0\n"
                "LDR     R0, [R5,#4]\n"
                "CMP     R0, #1\n"
                "LDRNE   R1, =0x146\n"
                "LDRNE   R0, =0xFF8AF310\n"
                "BLNE    sub_FF81E88C\n"
                "CMN     R4, #0xC00\n"
                "LDREQSH R4, [R5,#2]\n"
                "CMN     R4, #0xC00\n"
                "MOVEQ   R1, #0x14C\n"
                "LDREQ   R0, =0xFF8AF310\n"
                "STRH    R4, [R5,#2]\n"
                "BLEQ    sub_FF81E88C\n"
                "MOV     R0, R4\n"
                //"BL      sub_FFA14A7C\n"
				"BL      apex2us\n"  // +
                "MOV     R4, R0\n"
                "BL      sub_FF8F901C\n"
                "MOV     R0, R4\n"
                "BL      sub_FF8FF29C\n"
                "TST     R0, #1\n"
                "LDRNE   R1, =0x151\n"
                "LDMNEFD SP!, {R4-R6,LR}\n"
                "LDRNE   R0, =0xFF8AF310\n"
                "BNE     sub_FF81E88C\n"
                "LDMFD   SP!, {R4-R6,PC}\n"
     );
};
